package cn.zjutleo.village_server.controller;

import cn.zjutleo.village_server.entity.AddressData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import cn.zjutleo.village_server.service.AddressDataService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 张坤
 * @DateTime: 2021/9/30 12:36
 * @Description: 该类用于 TODO
 */
@Api(tags = "地区名称和行政代码获取")
@RestController()
public class AddressDataController {
    @Autowired
    AddressDataService addressDataService;

    @ApiOperation("根据传入的行政代码获取其下一级的所有地区的信息")
    @GetMapping("/api/selectAddressData/{code}")
    public List<AddressData> getAddressCode(@PathVariable String code){
        switch (code.length()){
            case 2:return addressDataService.getCtites(code);
            case 4:return addressDataService.getAreas(code);
            case 6:return addressDataService.getStreets(code);
            case 9:return addressDataService.getVillages(code);
            default:return addressDataService.getAllProvinces();
        }
    }
}
